home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / (Demos) / TestAssign.c < prev    next >
C/C++ Source or Header  |  1995-11-08  |  5KB  |  149 lines

  1. /*
  2. TestAssign.c
  3.  
  4. This is significantly more complicated than it needs to be. The fancy stuff
  5. is merely to put Assign.c through its paces. In particular, if the array a[]
  6. didn't change dimensions from block to block in testAssign1 then we could
  7. read the whole file by a single call to ReadAssignmentFile, instead of
  8. opening the file and making repeated calls to ReadAssignmentBlock, etc.
  9.  
  10. For a good example of the use of Assign, see ReadLuminanceRecord.c.
  11.  
  12. HISTORY:
  13. 8/93    dgp    created this new version, which cobbles together several older versions.
  14. 8/12/93    dgp    updated to work with new Assign.c
  15. 9/8/93    dgp    call Require() and use new AllocateDescriptions.
  16. 9/5/94 dgp removed assumption in printf's that int==short.
  17. 11/8/95 dgp tracked down and fixed bug in Assign.c, the Description was being corrupted
  18. by freeing an unallocated variable. The fix is marked by "11/18/95".
  19. */
  20. #include "VideoToolbox.h"
  21. #if MAC_C
  22.     #include "Luminance.h"
  23. #endif
  24. #define PREFERENCES_FOLDER 0
  25. void moreTests(void);
  26. void main(void);
  27.  
  28. typedef struct {
  29.     double *a,logC,viewingDistance;
  30.     long trials;
  31.     char *message;
  32.     unsigned char *m;
  33. } Psychophysics;
  34. Description *DescribePsychophysics(Psychophysics *p);
  35.  
  36. Description *DescribePsychophysics(Psychophysics *p)
  37. {
  38.     Description *d;
  39.     int i;
  40.     
  41.     d=AllocateDescriptions(10);
  42.     i=0;
  43.     d[i++]=Describe(stringType,&p->message,"message",NULL);
  44.     d[i++]=Describe(unsignedCharPtrType,&p->m,"m",NULL);
  45.     d[i++]=Describe(doublePtrType,&p->a,"a",NULL);
  46.     d[i++]=Describe(shortType,&p->trials,"trials",NULL);
  47.     d[i++]=Describe(doubleType,&p->viewingDistance,"viewingDistance",NULL);
  48.     d[i++]=Describe(doubleType,&p->logC,"logC",NULL);
  49.     assert(i<=10);        /*  make sure array was big enough */
  50.     d[i++]=NullDescription();        /*  mark end of array */
  51.     return d;
  52. }
  53.  
  54. void main(void)
  55. {
  56.     Description *d;
  57.     static Psychophysics psychophysics,*p;
  58.     short i,j,flags=assignReportUnknown;//assignEchoFile | assignEchoAssignments;
  59.     FILE *stream;
  60.     char filename[]="testAssign1";
  61.     
  62.     StackGrow(20000);
  63.     Require(0);
  64.     #if MAC_C
  65.         MaximizeConsoleHeight();
  66.     #endif
  67.     p=&psychophysics;
  68.     d=DescribePsychophysics(p);
  69.     InitializeDescribedVars(d,flags);
  70.     stream=fopen(filename,"r");
  71.     do{
  72.         printf("\n/******** New block ********/\n");
  73. //        i=ReadAssignmentLine(stream,d,flags);
  74.         ReadAssignmentBlock(stream,d,flags);
  75.             /* a real program would do something useful here with the data in p */
  76.             /* instead we fool around with print statements */
  77.             PrintAssignments(stdout,d,flags);
  78.             printf("Now dimensioned as a");
  79.             for(i=0;;i++){
  80.                 j=FindDescribedDim(d,&p->a,i,flags);
  81.                 if(j<=0)break;
  82.                 printf("[%d]",(int)j);
  83.             }
  84.             printf(".\n");
  85.         FreeDescribedPtrVars(d,flags);
  86.     } while(!feof(stream));
  87.     fclose(stream);
  88.     FreeDescribedVars(d,flags);
  89.     FreeDescriptions(d);
  90.     if(0)moreTests();
  91. }
  92. void moreTests(void)
  93. {
  94.     static double logC,maskLogC,viewingDistance,*a,conditionLogC[4],conditionMaskLogC[4];
  95.     short trials,i,flags;
  96.     static char *kindOfTrial,*message,image[1000];
  97.     unsigned char *m;
  98.     Description *d;
  99.     FILE *stream;
  100.     static char filename[]="testAssign2";
  101.     int error;
  102.     static double b[2][2],c[1][2][3];
  103.     
  104.     flags=assignReportUnknown;
  105.     
  106.     printf("\n\n\nMore tests.\n");
  107.     #ifdef _LUMINANCE_
  108.         if(1){
  109.             static LuminanceRecord LR;
  110.             
  111.             // Test ReadLuminanceRecord.c
  112.             if(PREFERENCES_FOLDER)error=OpenPreferencesFolder();
  113.             i=ReadLuminanceRecord("LuminanceRecord1.h",&LR,flags);
  114.             if(PREFERENCES_FOLDER)error=ClosePreferencesFolder();
  115.             if(i<=0)PrintfExit("Couldn't read LuminanceRecord, error %d.\n",(int)i);
  116.             i=WriteLuminanceRecord("LR.h",&LR,flags);
  117.             if(i<=0)PrintfExit("Couldn't write/verify LuminanceRecord, error %d.\n",(int)i);
  118.             printf("ReadLuminanceRecord.c seems to work fine. Created LR.h\n\n");
  119.         }
  120.     #endif
  121.     #if 1
  122.         /* parse testAssign2 */
  123.         d=AllocateDescriptions(14);
  124.         i=0;
  125.         d[i++]=Describe(doublePtrType,&a,"a","array");
  126.         d[i++]=Describe(unsignedCharPtrType,&m,"m","chars");
  127.         d[i++]=DescribeArray(charType,&image,"image","Image data",100L,0L);
  128.         d[i++]=Describe(stringType,&message,"message",NULL);
  129.         d[i++]=Describe(doubleType,&logC,"logC","log contrast");
  130.         d[i++]=Describe(doubleType,&maskLogC,"maskLogC",NULL);
  131.         d[i++]=Describe(stringType,&kindOfTrial,"kindOfTrial",NULL);
  132.         d[i++]=Describe(doubleType,&viewingDistance,"viewingDistance","inches");
  133.         d[i++]=Describe(shortType,&trials,"trials",NULL);
  134.         d[i++]=DescribeArray(doubleType,&b,"b",NULL,2L,2L,0L);
  135.         d[i++]=DescribeArray(doubleType,&c,"c",NULL,1L,2L,3L,0L);
  136.         assert(i<=14);                                /* make sure array was big enough */
  137.         d[i++]=NullDescription();                    /* mark end of array */
  138.         InitializeDescribedVars(d,0);
  139.         stream=fopen(filename,"r");
  140.         ReadAssignmentLine(stream,d
  141.             ,assignHexFloats|assignReportUnknown|assignEchoAssignments);
  142.         FreeDescribedVars(d,0);
  143.         fclose(stream);
  144.         ReadAssignmentFile(filename,d,assignHexFloats|assignReportUnknown);
  145.         PrintAssignments(stdout,d,0);
  146.         FreeDescriptions(d);
  147.     #endif
  148. }
  149.